/**********************************
 * 文件:硬件驱动 动态库
 * 创建者:华磊
 * 创建时间:2020.11.21
 * copyright:(c)深圳市华友高科有限公司
 * 备注:基于原HMI的硬件驱动部分整合与修改,因不符合目前编写规范的代码涉及关联较多,修改量大,暂时不作规范性修改
 * 修改者:
 **********************************/

#ifndef DEVICEDRIVER_H
#define DEVICEDRIVER_H

#include "devicedriver_global.h"

#if QT_VERSION<0x050000
#include "ipmethod.h"
#else
class frmInput;
#endif
#include "deviceButton/threadencoder.h"
#ifdef D_USE_HUATU
#include "deviceButton/threaddev.h"
#else
#include "deviceButton/threaddevlang.h"
#endif

#include <QTimer>
#include <QMutex>
//引用枚举
#include "../CommunicateDelegate/moveoperation.h"


/**
 * @brief The DeviceDriver class        硬件驱动库 类
 */
class DEVICEDRIVERSHARED_EXPORT DeviceDriver : public QObject
{
    Q_OBJECT
public:
    DeviceDriver(MoveOperation *moveOperationIn, GlobalData *globalDataIn, QString workDirIn);

public slots:
    void setBuzzerPlay_slot();
    void pendentKeyEvent_Slot(unsigned int nKey, int nValue);
    void KeyReadEncoderSlot(unsigned short code, int val);
    void wheelTimeWork();

signals:
    void keyStartPress();
    void keyStartRelease();
    void keyStop();
    void keyPause();
    void keyReturnZero();
    void keyBack();

    void keyFunctionL1Press();
    void keyFunctionL1Release();
    void keyFunctionL2Press();
    void keyFunctionL2Release();
    void keyFunctionL3Press();
    void keyFunctionL3Release();
    void keyFunctionL4Press();
    void keyFunctionL4Release();


    void keyFunctionR1Press();
    void keyFunctionR1Release();
    void keyFunctionR2Press();
    void keyFunctionR2Release();
    void keyFunctionR3Press();
    void keyFunctionR3Release();

    void scrollLeft(int speedValue);
    void scrollRight(int speedValue);//速度值

    void velIncrease_signal();
    void velDecrease_signal();
    void stepModeChange_signal();
    void jogCoordinateChange_signal();
    void jogCoordinateChangeTool_signal();
    void robotChange_signal();
    void servoOn_signal(int isOn);
    void clearMessage_signal();





signals:
    /**
     * @brief msgBoxSignal                      通知 打开消息框
     */
    void msgBoxSignal(int type,QString title,QString text);
    void closeBoxSignal();

    /**
     * @brief changeViewIDsignal        切换中部页面(eg 点击寸动按键,需要返回寸动界面)
     * @param id
     */
    //void changeViewIDsignal(int id);
    void setRightViewCurrentAxis(int axisID);

    /**
     * @brief sendHandWheel 滚轮运动 轴 方向 值
     */
    void sendHandWheel(int axis ,int direction ,int value);

private:

#if QT_VERSION<0x050000
    /**
     * @brief inputmethod       软键盘
     */
    INPUTMethod *inputmethod;
#else
    frmInput *inputmethod_qt5;
#endif

    /**
     * @brief volumPlayerFlag   按键声 开启 关闭 标志位
     */
    int volumPlayerFlag;



    /**
     * @brief encoderFlag       滚轮 开启 关闭 标志位
     */
    int encoderFlag;
    /**
     * @brief threadDev         驱动:硬按键 实例
     */
    ThreadDev* threadDev;
    /**
     * @brief encoder           驱动:编码器(滚轮) 实例
     */
    ThreadEncoder  *encoder;

    /**
     * @brief lockWin                           当前状态是否锁屏
     */
    bool lockWin;



    Ros::E_KEY lastKey;

    MoveOperation *moveOperation;
    GlobalData *globalData;

    /**
     * @brief jogTimer      滚轮寸动定时器
     */
    QTimer *wheelTimer;
    /**
     * @brief axisNumber    当前轴
     */
    int axisNumber;
    /**
     * @brief direction     方向
     */
    int direction;

    bool wheelFlag;

};

#endif // DEVICEDRIVER_H
